const reminderFox_HOUR_TIMEOUT = 1800000; // changed to half hour instead of 1 hour= 3600000 // dump: externalize this to a pref (read it first time only; then store it)
const reminderFox_ALARM_DELAY = 4000; // make sure 500ms between each alarm, or mozilla creates a blank window
var reminderFox_alarmList = new Array();
var reminderFox_lastStatusBarClick;
var reminderFox_initialized = false;
// Cache the last reminders
var reminderFox_lastDay = null;
var reminderFox_lastAlarmTime = null;
// Launches the 'edit reminder' dialog, fills in Reminders list
function reminderFox_openAddRemindersDialog( closeIfOpen ) {
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
var topWindow = windowManagerInterface.getMostRecentWindow("window:reminderFoxEdit");
if (reminderOrTodo.alarmLastAcknowledge == null || reminderOrTodo.alarmLastAcknowledge <= alarmTime) {
var windowEnumerator = reminderFox_getWindowEnumerator();
if (windowEnumerator.hasMoreElements()) {
var oldestWindow = windowEnumerator.getNext();
for (var i = 0; i < oldestWindow.reminderFox_alarmList.length; i++) {
var currentAlarmId = oldestWindow.reminderFox_alarmList[i].alarmId;
var snooze = false;
if (currentAlarmId == alarmReminderId) {
if (oldestWindow.reminderFox_alarmList[i].snoozed) {
snooze = true;
}
var currentAlarmTime;
if (snooze) {
var alarmTimeInt = parseInt(alarmTime);
var actualCurrentTime = new Date().getTime();
// if you snooze an alarm for a long value (like 28 days), mozilla calls the setTimeout immediately. We need
// to check against that (they probably have some bug when an int value gets too big)
actualCurrentTime = actualCurrentTime + 2000; // add 2 seconds for a small buffer
var diffcheck = actualCurrentTime < alarmTimeInt;
if (actualCurrentTime < alarmTimeInt) {
reminderFox_logMessageLevel("alarm: current time is less than alarm time; not showing alarm. Current time " + (actualCurrentTime - 2000) + "; alarm time set for: " + alarmTimeInt, REMINDER_FOX_LOG_LEVEL_SUPER_FINE); //TODO
// ensure that the current stored alarm time is the same as the alarm time this function was called with.
// This check is in case the user changed the alarm time after the first timeout had been issued. You only
// want to show one alert at the last time the user selected
if (alarmTimeDiff >= -60000 && alarmTimeDiff <= 60000) {
if (!snooze && missedAlarm == "false") { // don't check, if this is a past alarm (times won't match because it was set to go off not at current time, but a previous time)
// secondary check - in case of FireFox setTimeout Bug;
// check if the current time is about when the alarm was set for
var currentSystemTime = new Date().getTime();
var alarmSystemTimeDiff = alarmTime - currentSystemTime;
if (alarmSystemTimeDiff < -60000 || alarmSystemTimeDiff > 60000) {
reminderFox_logMessageLevel("alarm: system time diff failed check; returning: " + alarmSystemTimeDiff, REMINDER_FOX_LOG_LEVEL_SUPER_FINE); //TODO
continue;
}
}
// Mozilla bug: it seems that if you open two alarm dialog windows at the same time, only one of the loadAlarm() functions gets called
// from the new window. So we introduce a small second delay between opening each alarm - so if you have several alarms set to go off
// at the same time, you will always see them properly and not get a blank window in one of them
if ( ignoreCheck || alarmArray.length > 1 || // if there's multiple reminders; continue in here. Only if there is 1 reminder would we want to set the delay
var origFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
origFile.initWithPath( baseFilePath );
var file2 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file2.initWithPath( filePath2 );
var file1 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file1.initWithPath( filePath1 );
// only write backup file if it differs from current file
if ( !file1.exists() || file1.lastModifiedTime != origFile.lastModifiedTime) {
// no file2 - create it
if ( !file2.exists() ) {
// bak2 doesn't exist. Let's just write out to it
var leafName = file2.leafName;
var parentDir = file2.parent;
if ( file1.exists() ) {
// copy bak1 to bak2
var parentDir = file2.parent;
var leafName = file2.leafName;
file1.copyTo( parentDir, leafName);
}
}
else if ( file1.exists() && file1.lastModifiedTime != file2.lastModifiedTime) { // and only write out if backup2 file is actually different than backup1
var timeDifference = file1.lastModifiedTime - file2.lastModifiedTime;
// only copy bak1 to bak2 if it is over a day old
if ( timeDifference > REMINDER_FOX_ONE_DAY ) { // greater than a day old; update
// copy bak2 to bak3
var file3 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);